{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: deckhouse
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "prometheus" "main")) | nindent 2 }}
spec:
  jobLabel: app
  podMetricsEndpoints:
  - port: self
    path: "/metrics"
    relabelings:
    - sourceLabels: [__meta_kubernetes_pod_container_port_number]
      regex: "9650"
      action: keep
    - regex: endpoint|namespace|container
      action: labeldrop
    - targetLabel: tier
      replacement: cluster
    - targetLabel: scrape_source
      replacement: self
    metricRelabelings:
    # Drop all buckets
    - sourceLabels: [__name__]
      regex: 'deckhouse_module_hook_run_seconds_bucket|deckhouse_kube_jq_filter_duration_seconds_bucket|deckhouse_kube_event_duration_seconds_bucket|deckhouse_helm_operation_seconds_bucket|deckhouse_module_hook_run_sys_cpu_seconds_bucket|deckhouse_module_hook_run_user_cpu_seconds_bucket|deckhouse_tasks_queue_action_duration_seconds_bucket|deckhouse_module_helm_seconds_bucket|deckhouse_module_run_seconds_bucket'
      action: drop
  - port: self
    path: "/metrics/hooks"
    relabelings:
    - regex: endpoint|namespace|container
      action: labeldrop
    - targetLabel: tier
      replacement: cluster
    - targetLabel: scrape_source
      replacement: hooks
  selector:
    matchLabels:
      app: deckhouse
  namespaceSelector:
    matchNames:
    - d8-system
{{- end }}
